package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.OrderReturnReason;
import com.itheima.manager.OrderReturnReasonManager;
import com.itheima.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/returnReason")
public class orderReturnReasonController {

    @Autowired
    private OrderReturnReasonManager orderReturnReasonManager;


    @GetMapping("/list")
    public R list(@RequestParam(defaultValue = "1") Integer pageNum,
                  @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult result = orderReturnReasonManager.list(pageNum, pageSize);
        return R.success(result);
    }


    @GetMapping("/{id}")
    public R select(@PathVariable Long id) {
        OrderReturnReason orderReturnReason = orderReturnReasonManager.select(id);
        return R.success(orderReturnReason);
    }


    @PostMapping("/update/{id}")
    public R updateReturnReason(@PathVariable Long id, @RequestBody OrderReturnReason reason) {
        Integer count = orderReturnReasonManager.updateReturnReason(id, reason);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }

    @PostMapping("/update/status")
    public R updateStatus(@RequestParam("ids") Long id, @RequestParam Integer status) {
        Integer count = orderReturnReasonManager.updateStatus(id, status);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }


    @PostMapping("/delete")
    public R delete(@RequestParam List<Long> ids) {
        Integer count = orderReturnReasonManager.delete(ids);
        if (count == null) {
            return R.error("删除失败");
        }
        return R.success("删除成功");
    }


    @PostMapping("/create")
    public R create(@RequestBody OrderReturnReason reason) {
        Integer count = orderReturnReasonManager.create(reason);
        if (count == null) {
            return R.error("删除失败");
        }
        return R.success("删除成功");
    }
}
